package com.mycoffee.ui;

import com.example.mycoffee.R;
import com.mycoffee.utils.NotifyingScrollView;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.Toast;

@SuppressLint("NewApi")
public class Message extends Activity {
	 
	private Drawable actionBarbackgroundDrawable;
	private LinearLayout search1;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		search1=(LinearLayout) findViewById(R.id.search_bar);
//		search1.setAlpha(10);
		actionBarbackgroundDrawable=getResources().getDrawable(R.drawable.ab_background);
        actionBarbackgroundDrawable.setAlpha(0);

        getActionBar().setBackgroundDrawable(actionBarbackgroundDrawable);
        ((NotifyingScrollView)findViewById(R.id.scroll_view)).setOnScrollChangedListener(onScrollChangedListener);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        	actionBarbackgroundDrawable.setCallback(mDrawableCallback);
        }
    }

	private NotifyingScrollView.OnScrollChangedListener onScrollChangedListener=new NotifyingScrollView.OnScrollChangedListener(){
		@Override
        public void OnScrollChanged(ScrollView who, int l, int t, int oldl, int oldt) {
            final int headerHeight=findViewById(R.id.first).getHeight()-getActionBar().getHeight();
            final float ratio=(float) Math.min(Math.max(t, 0), headerHeight) / headerHeight;
            final int newAlpha=(int)(ratio*255);
            actionBarbackgroundDrawable.setAlpha(newAlpha);
        }
    };
    private Drawable.Callback mDrawableCallback = new Drawable.Callback() {
        @Override
        public void invalidateDrawable(Drawable who) {
            getActionBar().setBackgroundDrawable(who);
        }

        @Override
        public void scheduleDrawable(Drawable who, Runnable what, long when) {
        }

        @Override
        public void unscheduleDrawable(Drawable who, Runnable what) {
        }
    };
//    
    
}
